﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common
{
    /// <summary>
    /// 服务注入
    /// 
    /// 第一步：
    /// 启动类里面加入
    /// services.AutoInjection();
    ///
    /// 第二步：
    /// 实现类上面加入特性类
    /// [Injection(typeof(IService),InjectionType.Scoped)]
    /// public class ServiceImpl : IService
    /// {
    ///     // 业务代码
    /// }
    /// 
    /// </summary>
    [AttributeUsage(AttributeTargets.Class)]
    public class InjectionAttribute : Attribute
    {
        /// <summary>
        /// 接口类型
        /// </summary>
        public Type InterfaceType { get; set; }

        /// <summary>
        /// 注入类型
        /// </summary>
        public InjectionType InjectionType { get; }

        /// <summary>
        /// 服务注入
        /// </summary>
        public InjectionAttribute()
        {
            this.InjectionType = InjectionType.Scoped;
        }

        /// <summary>
        /// 服务注入
        /// </summary>
        /// <param name="injectionType">注入类型</param>
        public InjectionAttribute(InjectionType injectionType)
        {
            this.InjectionType = injectionType;
        }

        /// <summary>
        /// 服务注入
        /// </summary>
        /// <param name="interfaceType">服务的接口类型</param>
        /// <param name="injectionType">注入的类型</param>
        public InjectionAttribute(Type interfaceType, InjectionType injectionType)
        {
            this.InterfaceType = interfaceType;
            this.InjectionType = injectionType;
        }
    }
}
